package models.statistics;

import exceptions.InvalidParameterException;
import models.CompressionAlgorithmType;
import models.FileInfo;

import javax.persistence.*;

@Entity
@Table(name = "LZ77Statistics")
public class LZ77Statistics extends CompressionStatsBase implements ICompressionStats {


    @Id
    @Column(name = "id", length = 50)
    public String id;

    @Column(name = "numberOfFactors")
    public long numberOfFactors;

    @Column(name = "compressingTime")
    public long compressingTime;

    @OneToOne(cascade = CascadeType.ALL)
    public FileInfo fileInfo;

    public LZ77Statistics() {
    }

    public LZ77Statistics(String id, long numberOfFactors, long compressingTime, FileInfo fileInfo) {
        this.id = id;
        this.numberOfFactors = numberOfFactors;
        this.compressingTime = compressingTime;
        this.fileInfo = fileInfo;
    }

    @Override
    public long calcTextSize(int reductionRate) throws InvalidParameterException {
        return calcReducedValue(fileInfo.fileSize, reductionRate);
    }

    @Override
    public float calcCompressionRate() {
        return calcCompressionRate(fileInfo.fileSize, numberOfFactors);
    }

    @Override
    public long calcCompressionTime(int reductionRate) throws InvalidParameterException {
        return calcReducedValue(compressingTime, reductionRate);
    }

    @Override
    public CompressionAlgorithmType algorithmType() {
        return CompressionAlgorithmType.lz77;
    }
}
